Button = {}
function Button:new(...)
    local o = {}
    setmetatable(o, {__index = Button})
    o:initialize(unpack(arg))
    return o
end

function Button:initialize(nation, template, x, y, quad, callback)
    local image = "resource/" .. nation .. template.imageName
    self.template = template
    self.image = love.graphics.newImage(image)
    self.quad = self:createQuad(quad)
    self.position = {x = x, y = y}
    self.size = {x = 60, y = 36}
    self.callback = callback
end

function Button:createQuad(quad)
    local quadXSize = self.image:getWidth() / self.template.sprites.lenX
    local quadYSize = self.image:getHeight() / self.template.sprites.lenY
    local x = (quad - 1) % self.template.sprites.lenX
    local y = math.floor((quad - 1) / self.template.sprites.lenX)
    return love.graphics.newQuad(
        x * quadXSize, y * quadYSize,
        quadXSize, quadYSize,
        self.image:getWidth(), self.image:getHeight()
    )
end

function Button:draw()
    local b, p = 2, 2
    love.graphics.setColor(255, 255, 255)
    love.graphics.rectangle(
        "fill", self.position.x, self.position.y,
        self.size.x + b * 2, self.size.y + b * 2
    )

    love.graphics.setColor(171, 180, 111)
    love.graphics.rectangle(
        "fill", self.position.x + b, self.position.y + b,
        self.size.x, self.size.y
    )

    love.graphics.setColor(255, 255, 255)
    love.graphics.drawq(
        self.image, self.quad,
        self.position.x, self.position.y
    )
end

function Button:inCoordinates(x, y)
    return (self.position.x + self.size.x >= x and self.position.x <= x) and
        (self.position.y + self.size.y >= y and self.position.y <= y)
end

function Button:update(dt) end
